IF exists(SELECT * FROM dbo.sysobjects WHERE name='WEB_menuLerenStuderenCategorie' AND xtype='P') 
BEGIN
	DROP PROCEDURE WEB_menuLerenStuderenCategorie
END
GO

create procedure WEB_menuLerenStuderenCategorie(@iNr char(7))
as
set nocount on
select lerenStuderen as menu, lerenStuderenCategorie as kies 
	from (select lerenStuderen from leerlingen..menuLerenStuderen union
	      select lerenStuderenCategorie from leerlingen..persoonlijkeGegevens2
	 	where inschrijvingsNr=@iNr
		and lerenStuderenCategorie is not null)  as m 
	 left join (select lerenStuderenCategorie from leerlingen..persoonlijkeGegevens2
	 where inschrijvingsNr=@iNr) as p
	 on p.lerenStuderenCategorie = m.lerenStuderen 